package com.fr.web;

import com.fr.base.CodeUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.html.Tag;
import com.fr.base.core.json.JSONObject;
import com.fr.privilege.authentication.Authentication;
import com.fr.privilege.authentication.AuthenticationFactory;
import com.fr.util.Base64;
import com.fr.web.core.SessionIDInfor;
import com.fr.web.core.WebUtils;
import java.awt.Image;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

public class Repository
{
  private HttpServletRequest req;
  private SessionIDInfor sessionIDInfor;
  private String servletURL;
  private Browser browser;
  private Authentication authentication;

  public Repository(HttpServletRequest paramHttpServletRequest, SessionIDInfor paramSessionIDInfor)
  {
    this.req = paramHttpServletRequest;
    this.sessionIDInfor = paramSessionIDInfor;
    this.servletURL = WebUtils.createServletURL(paramHttpServletRequest);
    this.browser = Browser.resolve(paramHttpServletRequest);
    this.authentication = AuthenticationFactory.extractAuthentication(paramHttpServletRequest);
  }

  public Browser getBrowser()
  {
    return this.browser;
  }

  public Authentication getCurrentAuthentication()
  {
    return this.authentication;
  }

  public String checkoutReportletPath(String paramString)
  {
    return this.servletURL + "?reportlet=" + CodeUtils.encodeURIComponent(CodeUtils.cjkEncode(paramString));
  }

  public String checkoutResourcePath(String paramString)
  {
    return this.servletURL + "?op=resource&resource=" + CodeUtils.encodeURIComponent(CodeUtils.cjkEncode(paramString));
  }

  public String checkoutImage(Image paramImage)
  {
    if (this.browser.supportIMAGEBase64Decode())
      return "data:image/png;base64," + Base64.encode(paramImage, "png");
    return this.servletURL + "?op=attach_image&id=" + this.sessionIDInfor.addReportPageImage(paramImage);
  }

  public String checkoutWidgetUrl(JSONObject paramJSONObject, String paramString)
  {
    return this.servletURL + "?op=widget" + ((paramString == null) ? "" : new StringBuffer().append("&ftype=").append(paramString).toString()) + "&location=" + paramJSONObject.toString() + "&sessionID=" + getSessionIDInfor().getSessionID();
  }

  public Tag checkoutImageTag(Image paramImage, int paramInt1, int paramInt2)
  {
    Tag localTag = new Tag("img").css("width", paramInt1 + "px").css("height", paramInt2 + "px").css("border", "0").attr("src", (paramImage == null) ? blank_image() : checkoutImage(paramImage));
    return localTag;
  }

  public Map checkoutTplContext()
  {
    Map localMap = WebUtils.createTemplateMap(this.req);
    localMap.put("sessionID", (this.sessionIDInfor == null) ? "" : this.sessionIDInfor.getSessionID());
    return localMap;
  }

  public Object checkoutParameterValue(String paramString)
  {
    return this.sessionIDInfor.getParameterValue(paramString);
  }

  public void writeTagBackground(Tag paramTag, Image paramImage, boolean paramBoolean)
  {
    String str = checkoutImage(paramImage);
    if ((this.browser.supportTransparentImage()) || (!(paramBoolean)))
      paramTag.css("background", "url(" + str + ") no-repeat");
    else
      paramTag.css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + str + "')");
  }

  public void writeTagBackground(Tag paramTag, Image paramImage)
  {
    writeTagBackground(paramTag, paramImage, true);
  }

  public boolean isShowParameterPanel()
  {
    return (!(ComparatorUtils.equals(WebUtils.getHTTPRequestParameter(this.req, "__pi__"), "false")));
  }

  private String blank_image()
  {
    return this.servletURL + "?op=resource&resource=/com/fr/web/images/s.gif";
  }

  public String getServletURL()
  {
    return this.servletURL;
  }

  public SessionIDInfor getSessionIDInfor()
  {
    return this.sessionIDInfor;
  }

  public boolean isNeedToolbar()
  {
    return (!("false".equalsIgnoreCase(WebUtils.getHTTPRequestParameter(this.req, "__showtoolbar__"))));
  }
}